<?php

namespace App\Containers\AppSection\Ban\Tasks;

use App\Containers\AppSection\Ban\Data\Repositories\BanRepository;
use App\Ship\Criterias\IsNullCriteria;
use App\Ship\Criterias\NotNullCriteria;
use App\Ship\Criterias\WhereIn;
use App\Ship\Parents\Tasks\Task;

class GetAllBansTask extends Task
{
    protected BanRepository $repository;

    public function __construct(BanRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run()
    {
        return $this->repository->paginate();
    }

    public function banned(): static
    {
        $this->repository->pushCriteria(new IsNullCriteria('unbanned_at'));

        return $this;
    }

    public function unbanned(): static
    {
        $this->repository->pushCriteria(new NotNullCriteria('unbanned_at'));

        return $this;
    }

    public function byBannableTypes($type): static
    {
        $this->repository->pushCriteria(new NotNullCriteria($type . '_id'));
        return $this;
    }
}
